Skip to content

Conversation

@TimBozeman
Copy link

@TimBozeman TimBozeman commented Jun 18, 2018

Hiya,

Thank you for git-sync. It's pretty awesome! I just signed the CLA. Can we add a chown flag please?

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 18, 2018
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jun 18, 2018
@TimBozeman
Copy link
Author

CLA check.

@TimBozeman TimBozeman closed this Jun 19, 2018
@jasperf
Copy link

jasperf commented Dec 22, 2020

Any news on this flag addition? Think being able to set group:user would be very useful.

@thockin
Copy link
Member

thockin commented Dec 22, 2020

Why not simply run it as the user/group you want?

@jasperf
Copy link

jasperf commented Dec 22, 2020

Well, I just tried this addition:

  allowPrivilegeEscalation: false
    readOnlyRootFilesystem: true
    runAsUser: 1000
    runAsGroup: 1000

just to test and see if it would become laradock/docker if that is what you meant? And yes, it seems to now store as user and group 1000. So later on I could use a www-data group uid and gui as well.

@thockin
Copy link
Member

thockin commented Dec 22, 2020 via email

@shubhamc183
Copy link

@thockin can you please let me know where I am going wrong.

I am not able to set the UID and GID of files properly

Even setting the runAsUser and fsGroup as same that worked at #146 (comment) throws the below-mentioned error.

INFO: detected pid 1, running init handler
I0309 12:47:59.450527      10 main.go:430]  "level"=0 "msg"="starting up"  "args"=["/git-sync"] "pid"=10
I0309 12:47:59.450647      10 main.go:694]  "level"=0 "msg"="cloning repo"  "origin"="git@bitbucket.org:org:XXXXXXX/YYY.git" "path"="//git"
E0309 12:47:59.453464      10 main.go:455]  "msg"="too many failures, aborting" "error"="Run(git clone --no-checkout -b master git@bitbucket.org:XXXXXXX/YYYYY.git //git): exit status 128: { stdout: \"\", stderr: \"fatal: could not create work tree dir '//git': Permission denied\\n\" }"  "failCount"=0

I am only able to set the group permission as 5000 and not able to provide UID for the checked-out file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: poc
spec:
  selector:
    matchLabels:
      app: poc
  replicas: 1
  template:
    metadata:
      labels:
        app: poc
    spec:
      securityContext:
        fsGroup: 5000
      containers:
        - name: busybox
          image: busybox
          volumeMounts:
          - name: buildproperties
            mountPath: /opt/data
            subPath: data
          stdin: true
      initContainers:
      - name: git-sync
        image: k8s.gcr.io/git-sync/git-sync:v3.2.2
        volumeMounts:
        - name: buildproperties
          mountPath: "/tmp/git/"
        - name: ssh-key
          mountPath: /etc/git-secret/
          readOnly: true
        env:
        - name: GIT_SYNC_SSH
          value: "true"
        - name: GIT_KNOWN_HOSTS
          value: "false"
        - name: GIT_SYNC_REPO
          value: git@bitbucket.org:XXX/YYYY.git
        - name: GIT_SYNC_BRANCH
          value: "master"
        - name: GIT_SYNC_DEST
          value: "data"
        - name: GIT_SYNC_ONE_TIME
          value: "true"
        - name: GIT_SYNC_PERMISSIONS
          value: "0777"
        - name: GIT_SYNC_ADD_USER
          value: "true"
      volumes:
      - name: buildproperties
        emptyDir: {}
      - name: ssh-key
        secret:
          secretName: bitbucket-ssh-key
          defaultMode: 0400

Inside the container busybox

/opt/data # ls -l
total 8
-rwxrwxrwx    1 65533    5000           565 Mar  9 12:44 README.md
-rwxrwxrwx    1 65533    5000            51 Mar  9 12:44 test.val

Can you please tell me how can I set the UID(1000) and GID(1001) for the checked-out files?

@aneesh-joseph

@thockin
Copy link
Member

thockin commented Mar 11, 2021

The default $HOME is /tmp:

$ docker run -ti --entrypoint sh k8s.gcr.io/git-sync/git-sync:v3.2.2 -c 'echo $HOME'
/tmp

The default git-root for git-sync is /tmp/git:

$ docker run -ti k8s.gcr.io/git-sync/git-sync:v3.2.2 | grep "root directory"
    	the root directory for git-sync operations, under which --dest will be created (default "/tmp/git")

Your log suggests that the root is being changed:

I0309 12:47:59.450647      10 main.go:694]  "level"=0 "msg"="cloning repo"  "origin"="git@bitbucket.org:org:XXXXXXX/YYY.git" "path"="//git"

Specifically: "path"="//git"

@shubhamc183
Copy link

I am facing this issue only when I add runAsUser: 1001.

I want to change the UID of the checked-out files. GID and permission I am able to change via securityContext.fsGroup and GIT_SYNC_PERMISSIONS respectively.

image

@shubhamc183
Copy link

After I changed the GIT_SYNC_ROOT to say(/workspace) it worked like charm.

Now, I can see my files cloned with UID: 1001, GID:5000, and expected permissions.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: poc
spec:
  selector:
    matchLabels:
      app: poc
  replicas: 1
  template:
    metadata:
      labels:
        app: poc
    spec:
      securityContext:
        runAsUser: 1001
        fsGroup: 5000
      containers:
        - name: busybox
          image: busybox
          volumeMounts:
          - name: buildproperties
            mountPath: /etc/data
            subPath: data
          stdin: true
      initContainers:
      - name: git-sync
        image: k8s.gcr.io/git-sync/git-sync:v3.2.2
        volumeMounts:
        - name: buildproperties
          mountPath: "/workspace"
        - name: ssh-key
          mountPath: /etc/git-secret/
          readOnly: true
        env:
        - name: GIT_SYNC_SSH
          value: "true"
        - name: GIT_KNOWN_HOSTS
          value: "false"
        - name: GIT_SYNC_REPO
          value: git@bitbucket.org:XXX/YYY.git
        - name: GIT_SYNC_BRANCH
          value: "master"
        - name: GIT_SYNC_DEST
          value: "data"
        - name: GIT_SYNC_ONE_TIME
          value: "true"
        - name: GIT_SYNC_PERMISSIONS
          value: "0777"
        - name: GIT_SYNC_ADD_USER
          value: "true"
        - name: GIT_SYNC_ROOT
          value: "/workspace"
      volumes:
      - name: buildproperties
        emptyDir: {}
      - name: ssh-key
        secret:
          secretName: bitbucket-ssh-key
          defaultMode: 0400

@thockin
Copy link
Member

thockin commented Mar 16, 2021 via email

@shubhamc183
Copy link

Is it documented somewhere? I was not able to find it.

If you want I can send a PR to add this note at the bottom of https://github.com/kubernetes/git-sync/blob/release-3.x/docs/ssh.md#step-3-configure-git-sync-container.

@thockin
Copy link
Member

thockin commented Mar 16, 2021 via email

@shubhamc183
Copy link

/workspace/max-mind in git-sync container is mounted to /opt/deployment/max-mind in application container where max-mind repo is being created with the required UID and GID as passed in the runAsUser and fsGroup of podSecurityContext.
image

But while using GIT_SYNC_PERMISSIONS, argument, as "0755" I am getting this below error.

INFO: detected pid 1, running init handler
I0317 12:48:55.834540      11 main.go:321]  "level"=0 "msg"="starting up"  "args"=["/git-sync"] "pid"=11
I0317 12:48:55.834621      11 main.go:574]  "level"=0 "msg"="cloning repo"  "origin"="git@bitbucket.org:XXXX/YYYY.git" "path"="/workspace"
I0317 12:49:26.223966      11 main.go:480]  "level"=0 "msg"="syncing git"  "hash"="719007cc322f9cd1d1e3141c99f899e2be860a8c" "rev"="HEAD"
I0317 12:49:27.144134      11 main.go:501]  "level"=0 "msg"="adding worktree"  "branch"="origin/feature_1.0" "path"="/workspace/rev-719007cc322f9cd1d1e3141c99f899e2be860a8c"
I0317 12:49:27.164566      11 main.go:524]  "level"=0 "msg"="reset worktree to hash"  "hash"="719007cc322f9cd1d1e3141c99f899e2be860a8c" "path"="/workspace/rev-719007cc322f9cd1d1e3141c99f899e2be860a8c"
I0317 12:49:27.164676      11 main.go:528]  "level"=0 "msg"="updating submodules"  
I0317 12:49:27.196228      11 main.go:541]  "level"=0 "msg"="changing file permissions"  "mode"="01363"
E0317 12:49:27.197236      11 main.go:347]  "msg"="failed to sync repo, aborting" "error"="error running command: exit status 1: { stdout: \"\", stderr: \"chmod: cannot read directory '/workspace/rev-719007cc322f9cd1d1e3141c99f899e2be860a8c': Permission denied\\n\" }"  

When I don't pass GIT_SYNC_PERMISSIONS I can manually go inside the application container and run chmod -R 755 /opt/deployment/max-mind successfully.

@thockin
Copy link
Member

thockin commented Mar 17, 2021

Hi, Can you please break this permissions issue report into a new issue with the smallest repro possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants